Skip to content

Add GitHub Actions workflow for auto-answering issues#5836

Open
trwalke wants to merge 9 commits intomainfrom
trwalke/addGhActionForIssues
Open

Add GitHub Actions workflow for auto-answering issues#5836
trwalke wants to merge 9 commits intomainfrom
trwalke/addGhActionForIssues

Conversation

@trwalke
Copy link
Copy Markdown
Member

@trwalke trwalke commented Mar 11, 2026

This pull request introduces a new GitHub Actions workflow to automatically respond to issues opened or labeled by trusted contributors. The workflow leverages Azure OpenAI to generate a friendly, informative reply and posts it as a comment on the issue. The automation is restricted to members, owners, collaborators, and contributors to prevent misuse.

Automated issue triage and response:

  • Added .github/workflows/auto-answer-issues.yml to enable automatic responses to issues using Azure OpenAI, triggered when issues are opened or labeled by trusted contributors.
  • Implemented environment variable checks and error handling to ensure required secrets and context are available before generating a response.
  • Integrated the @octokit/rest and openai Node.js packages to interact with GitHub and Azure OpenAI APIs for generating and posting replies.

Security and access control:

  • Restricted workflow execution to issues created by members, owners, collaborators, or contributors, preventing untrusted users from consuming API tokens.

@trwalke trwalke requested a review from a team as a code owner March 11, 2026 18:04
Copilot AI review requested due to automatic review settings March 11, 2026 18:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new GitHub Actions workflow intended to automatically generate and post responses to newly opened/labeled GitHub issues by running a Node.js script (with OpenAI + Octokit dependencies).

Changes:

  • Introduces .github/workflows/main.yml to trigger on issues events (opened, labeled).
  • Sets up Node.js 20, installs @octokit/rest and openai, then executes a repo script to generate/post a response.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5837, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5838, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5839, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5840, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5841, to work on those changes. Once the pull request is ready, I'll request review from you.

@trwalke
Copy link
Copy Markdown
Member Author

trwalke commented Mar 11, 2026

@copilot rename the file to auto-answer-issues.yml

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5842, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5843, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5844, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5845, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

@trwalke I've opened a new pull request, #5846, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI review requested due to automatic review settings March 11, 2026 22:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +7 to +9
permissions:
issues: write
contents: read
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job requests contents: read, but this workflow doesn’t appear to need repository contents (it only installs npm packages and calls GitHub/Azure OpenAI). For least-privilege, consider removing contents: read unless a later step truly requires it.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
- name: Checkout repository
uses: actions/checkout@v4

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actions/checkout step is not used by subsequent steps (the script is inline and dependencies are installed from the registry). Removing checkout reduces runtime and avoids granting/using repository content access unnecessarily.

Suggested change
- name: Checkout repository
uses: actions/checkout@v4

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +96
});
const botAlreadyCommented = comments.some(
(comment) => comment.user?.login === "github-actions[bot]"
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prompt hard-codes “An issue has been opened…”, but the workflow also runs on the labeled event. Consider adjusting the prompt text based on github.event.action so the model has accurate context (e.g., “opened” vs “labeled for auto-answer”).

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +128
- Uses markdown formatting suitable for a GitHub issue comment.
`;

const completion = await openai.chat.completions.create({
model: AZURE_OPENAI_DEPLOYMENT,
messages: [
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow always posts a new comment for every eligible opened/labeled event. There’s currently no guard for a specific label name and no check for whether the bot has already commented, so repeated labeling (or reopening) can spam issues and burn Azure OpenAI tokens. Consider (a) gating on a dedicated label (e.g. only when action == 'labeled' && label.name == 'auto-answer'), and/or (b) listing existing issue comments via Octokit and exiting early if a prior auto-answer marker/comment from the bot is already present.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@gladjohn gladjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we plan to turn off the issue sentinel workflow that get's triggered now?

trwalke and others added 8 commits March 19, 2026 20:27
This action will attempt to answer questions customers have when posted on the repo.
…hor_association (#5841)

* Initial plan

* Guard workflow against untrusted triggering using author_association

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

* Add COLLABORATOR and CONTRIBUTOR to author_association guard

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…issues.yml (#5842)

* Initial plan

* Rename main.yml to auto-answer-issues.yml

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
…5843)

* Initial plan

* Switch auto-answer-issues workflow from OpenAI.com to Azure OpenAI

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
…workflow (#5846)

* Initial plan

* Fix ESM/CJS issue: use dynamic import() for openai and @octokit/rest in workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
…s workflow (#5845)

* Initial plan

* Remove CONTRIBUTOR from author_association check in auto-answer-issues workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
* Initial plan

* Add duplicate comment detection to auto-answer-issues workflow

Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: trwalke <30090357+trwalke@users.noreply.github.com>
@bgavrilMS bgavrilMS force-pushed the trwalke/addGhActionForIssues branch from 7e8dbfc to 52a3945 Compare March 19, 2026 20:27
Copilot AI review requested due to automatic review settings April 1, 2026 22:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines +14 to +17
# Only run for issues created by org members or owners (i.e., Microsoft Open Source enterprise members).
# github.event.issue.author_association is set by GitHub based on the issue author's relationship
# to this repository. MEMBER = org member, OWNER = repo/org owner. This prevents untrusted
# external contributors from triggering the Azure OpenAI-backed responder and consuming secrets/tokens.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment claims this only runs for org members/owners and equates that to “Microsoft Open Source enterprise members”, but github.event.issue.author_association reflects repo/org relationship (not GitHub Enterprise membership). Please adjust this comment to accurately describe what’s enforced so readers don’t assume a stronger guarantee than exists.

Suggested change
# Only run for issues created by org members or owners (i.e., Microsoft Open Source enterprise members).
# github.event.issue.author_association is set by GitHub based on the issue author's relationship
# to this repository. MEMBER = org member, OWNER = repo/org owner. This prevents untrusted
# external contributors from triggering the Azure OpenAI-backed responder and consuming secrets/tokens.
# Only run for issues created by users who have a trusted relationship to this repo/org in GitHub
# (based on github.event.issue.author_association), such as MEMBER, OWNER, or COLLABORATOR.
# author_association reflects the issue author's relationship to this repository/organization only;
# it does NOT indicate GitHub Enterprise or "Microsoft Open Source enterprise" membership.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +22
if: |
github.event.issue.author_association == 'MEMBER' ||
github.event.issue.author_association == 'OWNER' ||
github.event.issue.author_association == 'COLLABORATOR'
steps:
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanatory comment says “Only run for issues created by org members or owners”, but the if: condition also allows COLLABORATOR. Either update the comment to include collaborators, or tighten the condition to match the stated restriction.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +22
if: |
github.event.issue.author_association == 'MEMBER' ||
github.event.issue.author_association == 'OWNER' ||
github.event.issue.author_association == 'COLLABORATOR'
steps:
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the automation is restricted to “members, owners, collaborators, and contributors”, but the workflow guard currently does not include CONTRIBUTOR. Either update the PR description to match the implementation, or add CONTRIBUTOR back if it’s intended to be allowed.

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +101
// Check if the bot has already commented on this issue to avoid duplicate responses.
const comments = await octokit.paginate(octokit.issues.listComments, {
owner: REPO_OWNER,
repo: REPO_NAME,
issue_number: issueNumber,
per_page: 100
});
const botAlreadyCommented = comments.some(
(comment) => comment.user?.login === "github-actions[bot]"
);
if (botAlreadyCommented) {
console.log("Bot has already commented on this issue. Skipping.");
return;
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate-response check treats any existing comment by github-actions[bot] as “already answered”. That’s overly broad (other workflows/actions can comment as github-actions[bot]) and can prevent this workflow from ever posting. Consider adding a unique marker to this workflow’s comment (e.g., an HTML comment tag) and checking for that marker instead.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants